package com.thenmorethings.interceptor;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.ActionProxy;
import com.opensymphony.xwork2.interceptor.Interceptor;

public class loginInterceptor implements Interceptor{

	@Override
	public void destroy() {
		
	}

	@Override
	public void init() {
		
	}

	@Override
	public String intercept(ActionInvocation invocation) throws Exception {
		
		ActionContext ac = invocation.getInvocationContext();
		
		ActionProxy proxy = invocation.getProxy();
		//获取当前action执行的方法名
		String methodName = proxy.getMethod();
		
		if(!"login".equals(methodName))
		{
			Object obj = ac.getSession().get("loginSession");
			if(obj == null)
			{
				//没有登陆
				return "loginu";
			}
			else
			{
				return invocation.invoke();
			}
		}
		else
		{
			//说明当前用户正在登陆
			return invocation.invoke();
		}
			
	}

}
